#include "StatementList.h"
#include "../GeneralVisitor.h"

StatementList::StatementList(std::vector<TreeNode*> iStatements)
{
    fStatements = iStatements;
}

StatementList::~StatementList()
{
    for(vector<TreeNode*>::iterator it = fStatements.begin(); it != fStatements.end(); ++it)
    {
        delete (*it);
    }

    fStatements.clear();
}

void StatementList::CheckVariables(set<string>& oVariables, string iParentName)
{
    for(vector<TreeNode*>::iterator it = fStatements.begin(); it != fStatements.end(); ++it)
    {
        (*it)->CheckVariables(oVariables, iParentName);
    }
}

void StatementList::CheckFunctionCalls(set<FunctionDefinition*>& iAllFunctions, string iParentName)
{
    for(vector<TreeNode*>::iterator it = fStatements.begin(); it != fStatements.end(); ++it)
    {
        (*it)->CheckFunctionCalls(iAllFunctions, iParentName);
    }
}

void StatementList::CheckClassConstructions(set<ClassDefinition*>& iAllClasses, string iParentName)
{
    for(vector<TreeNode*>::iterator it = fStatements.begin(); it != fStatements.end(); ++it)
    {
        (*it)->CheckClassConstructions(iAllClasses, iParentName);
    }
}

void StatementList::CheckExpressionTypes(map<string, ExpressionType*>& iVarTypes, string iParentName)
{
    for(vector<TreeNode*>::iterator it = fStatements.begin(); it != fStatements.end(); ++it)
    {
        (*it)->CheckExpressionTypes(iVarTypes, iParentName);
    }
}

ReturnStatement* StatementList::GetFirstReturnStatement()
{
    ReturnStatement* lResult;

    for(vector<TreeNode*>::iterator it = fStatements.begin(); it != fStatements.end(); ++it)
    {
        lResult = (*it)->GetFirstReturnStatement();

        if(lResult != 0)
            return lResult;
    }

    return 0;
}

void StatementList::Accept(GeneralVisitor* iVisitor)
{
    iVisitor->Visit(this);
}
